<template>
  <el-scrollbar 
    ref="scrollContainer"
    :vertical="false" 
    class="scroll-container" 
    @wheel.prevent="handleScroll"
  >
    <slot />
  </el-scrollbar>
</template>

<script setup>
import { ref, onMounted, onBeforeUnmount } from 'vue'

const props = defineProps({
  speed: {
    type: Number,
    default: 20
  }
})

const scrollContainer = ref(null)
let handleScrollFn = null

const handleScroll = (e) => {
  const eventDelta = e.wheelDelta || -e.deltaY * 40
  const $scrollWrapper = scrollContainer.value.wrap$
  $scrollWrapper.scrollLeft = $scrollWrapper.scrollLeft + eventDelta / 4
}

onMounted(() => {
  handleScrollFn = handleScroll
})

onBeforeUnmount(() => {
  handleScrollFn = null
})

defineExpose({
  scrollContainer
})
</script>

<style lang="scss" scoped>
.scroll-container {
  white-space: nowrap;
  position: relative;
  overflow: hidden;
  width: 100%;
  
  :deep(.el-scrollbar__bar) {
    bottom: 0px;
  }
  
  :deep(.el-scrollbar__wrap) {
    height: 49px;
  }
}
</style> 